﻿@model System.Data.DataTable
<form id="form1" method="post">
    <br />
    <table cellpadding="0" cellspacing="1" border="0" width="99%" class="formtable">
        <tr>
            <th style="width: 80px;">标题：</th>
            <td><input type="text" name="Title" id="Title" class="mytext" value="@(Model.Rows.Count>0?Model.Rows[0]["f1"].ToString():"")" validate="empty" errmsg="标题不能为空!" style="width: 75%" /></td>
        </tr>
        <tr>
            <th>内容：</th>
            <td><textarea class="mytextarea" name="Contents" id="Contents" model="html" validate="editor" errmsg="内容不能为空!" style="width: 75%;height:80px;">@(Model.Rows.Count>0?Model.Rows[0]["f2"].ToString():"")</textarea></td>
        </tr>
    </table>
    <div class="buttondiv">
        <input type="button" class="mybutton" value="保存" onclick="save(this);" />
        <input type="button" class="mybutton" value="退回" onclick="parent.flowBack(true);" />
        <input type="button" class="mybutton" value="发送" onclick="parent.flowSend(true);" />
    </div>
</form>
<script src="~/RoadFlowResources/scripts/ckeditor/ckeditor.js"></script>
<script src="~/RoadFlowResources/scripts/flowRun/form.js"></script>
<script>
    $(window).load(function () {
        var editor = CKEDITOR.replace("Contents", {
            height: 200,
            toolbarGroups: formLoad.ckeditor_toolbarFullGroups,
            filebrowserImageUploadUrl: '/RoadFlowCore/Controls/SaveCKEditorFiles'
        });

        //设置流程关联的业务表主键值
        $("#instanceid", parent.document).val("@RoadFlow.Utility.Tools.HttpContext.Request.Querys("instanceid")");

        //设置流程标题
        $("#customformtitle", parent.document).val($("#Title").val());

    });
    CKEDITOR.on('instanceReady', function (e) {
        parent.setIframeHeight(600);
    });
    function save(but) {
        var f = document.forms[0];
        if (new RoadUI.Validate().validateForm(f)) {
            var o = RoadUI.Core.serializeForm($(f));
            var contents = CKEDITOR.instances.Contents.getData();
            o.Contents = contents;
            $(but).prop("disabled", true);
            $.ajax({
                url: "SaveCustomForm@(Html.Raw(ViewData["queryString"]))", data: o, type: "post", dataType: "json", success: function (json) {
                    alert(json.message);
                    $(but).prop("disabled", false);
                    if (json.success == 1) {
                        window.location = 'Customform1?@(Html.Raw(ViewData["query"]))&instanceid=' + json.instanceid;
                    }
                }
            });
        }
    }
    
</script>